//
//  ZooLocation.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 7/23/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "ZooLocation.h"

@implementation ZooLocation
@synthesize cLatitude, cLongitude, geoCoder, sLocation;

-(id)init {
    self = [super init];
    if (self) {
        locationManage = [[CLLocationManager alloc]init];
        locationManage.delegate = self;
        currentLocation = [[CLLocation alloc]init];
        sLocation = [[NSString alloc]init];
        [locationManage startUpdatingLocation];
//        [self performSelector:@selector(stopUpdating) withObject:@"stop"];
    }
    
    return self;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    currentLocation = newLocation;

    sLocation = [NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude];
    cLatitude = currentLocation.coordinate.latitude;
    cLongitude = currentLocation.coordinate.longitude;
    
    NSLog(@"%f %f", cLatitude,cLongitude);
    [self performSelector:@selector(stopUpdating) withObject:@"stop" afterDelay:10]; 

}

- (void)stopUpdating {
    [locationManage stopUpdatingLocation];
    locationManage.delegate = nil;
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"Local service is disable");
}

/*
 *  distanceFromLocation:
 *
 *  Discussion:
 *    Returns the lateral distance from current location.
 *    distance in meters
 */
-(CLLocationDistance)calculateDistanceFromCurrent:(CLLocation *)location {
    NSLog(@"a zooLocation.m");
    NSLog(@"%f %f",self.cLatitude, self.cLongitude);
    CLLocation *cLocation = [[CLLocation alloc]initWithLatitude:self.cLatitude longitude:self.cLongitude];
    return [cLocation distanceFromLocation:location];
}

@end
